package com.haust.swiper.service.impl;

import com.haust.commons.pojo.HaustResult;
import com.haust.mapper.TbContentMapper;
import com.haust.pojo.TbContent;
import com.haust.swiper.cache.ContentCacheManagerImpl;
import com.haust.swiper.service.PortalSwiperService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

@Service
public class PortalSwiperServiceImpl implements PortalSwiperService {
//    @Value("${Haust.mysql.bigad.id}")
//    private Long swiperContentCategoryId; //内容分类主键--大广告

    @Autowired
    private TbContentMapper contentMapper;
    @Autowired
    private ContentCacheManagerImpl ContentCacheManagerImpl;

    /**
     * 查询轮播广告
     *
     * @return
     */
    @Override
    public HaustResult showBigAd() {
        List<TbContent> list = ContentCacheManagerImpl.getAllSwiperContents();
        //从大广告中随机取 5个作为结果
        //打乱顺序
        Collections.shuffle(list);
        //
        if (list.size() > 5) {
            return HaustResult.ok(list.stream().limit(5).collect(Collectors.toList()));
        } else {
            return HaustResult.ok(list);
        }
    }
}
